 using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL;
using Exportation;


namespace Prototype1
{
    
    public partial class TesteLogin : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            IEnumerable<ExpenseReport> er = ExpenseReport.GetAll("");
            er.GetType();
        }
        
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs ea)
        {  
            using (DataAccessDataContext da = new DataAccessDataContext())
            {
                IEnumerable<ExpenseReport> reports = null;
                var query = from e in da.ExpenseReports
                            where e.UserEmail.Equals("")
                            select e;
                if (query != null)
                    reports = query.AsEnumerable<ExpenseReport>();

                foreach (ExpenseReport e in reports)
                {
                    //ExcelExportation ee = new ExcelExportation();
                    IExportation ee = ExportationFactory.GetExportationType("Exportation.ExportationTypes.ExcelExportation, DAL");
                    ee.Export(e);
                }
            }
        }

    //    class ExportacionExcelLine
    //    {
    //        string type, description, value, date;

    //        public ExportacionExcelLine(string type, string description, string value, string date)
    //        {
    //            this.type = type;
    //            this.description = description;
    //            this.value = value;
    //            this.date = date;
    //        }

    //        public string Date
    //        {
    //            get { return date; }
    //            set { date = value; }
    //        }

    //        public string Value
    //        {
    //            get { return this.value; }
    //            set { this.value = value; }
    //        }

    //        public string Description
    //        {
    //            get { return description; }
    //            set { description = value; }
    //        }

    //        public string Type
    //        {
    //            get { return type; }
    //            set { type = value; }
    //        }
            
    //    }

    //    protected void Button1_Click(object sender, EventArgs ea)
    //    {
    //        string fileName = "c:\\tmp\\";
    //        string sheetName;
    //        //IEnumerable<ExpenseReport> reports = ExpenseReport.GetAll("");
    //        IEnumerable<ExpenseReport> reports = null;
    //        using (DataAccessDataContext da = new DataAccessDataContext())
    //        {
    //            var query = from e in da.ExpenseReports
    //                        where e.UserEmail.Equals("")
    //                        select e;
    //            if (query != null)
    //                reports = query.AsEnumerable<ExpenseReport>();


    //            List<ExportacionExcelLine> list;
    //            foreach (ExpenseReport e in reports)
    //            {
    //                fileName += "ExpenseExportation-" + e.Id + ".xls";
    //                sheetName = e.Name;
    //                list = new List<ExportacionExcelLine>();
    //                foreach (ExpenseLine line in e.ExpenseLines)
    //                {
    //                    string type = line.ExpenseType.Name;
    //                    string description = line.Description;
    //                    string value = Convert.ToString(line.Value);
    //                    string date = Convert.ToString(line.Date);
    //                    list.Add(new ExportacionExcelLine(type, description, value, date));
    //                }
    //                DAL.ExcelGenerator.GenerateBinaryXls(list,
    //                    typeof(ExportacionExcelLine),
    //                    fileName, sheetName, GetSourceDictionary());
    //                fileName = ConfigurationManager.AppSettings["exportsDest"];
    //            }
    //            //FileStream file = File.Create(fileName);
    //            //file.Close();

    //            //List<MyObject> list = new List<MyObject>();
    //            //list.Add(new MyObject("Slb", "O maior"));
    //            //list.Add(new MyObject("Fcp", "curruptos"));


    //        }
    //    }
    //    public static Dictionary<string, string> GetSourceDictionary()
    //    {
    //        //Translation dictionary
    //        Dictionary<string, string> dict = new Dictionary<string, string>();
    //        dict.Add("Type", "Tipo");
    //        dict.Add("Date", "Data");
    //        dict.Add("Description", "Descrição");
    //        dict.Add("Value", "Valor");
            
    //        return dict;
    //    }
    }
}
